package com.probox.common.entity.service.customer.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Arrays;
import java.util.List;

import com.probox.common.core.utils.StringUtils;
import com.probox.common.entity.service.customer.IPaymentRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.probox.common.entity.mapper.customer.PaymentRuleMapper;
import com.probox.common.entity.domain.customer.PaymentRule;
import org.springframework.transaction.annotation.Transactional;

/**
 * 付费规则Service业务层处理
 *
 * @author zsy
 * @date 2021-05-27
 */
@Service
@Transactional
public class PaymentRuleServiceImpl extends ServiceImpl<PaymentRuleMapper, PaymentRule> implements IPaymentRuleService
{
    @Autowired
    private PaymentRuleMapper paymentRuleMapper;


    /**
     * 查询付费规则
     *
     * @param ruleId 付费规则ID
     * @return 付费规则
     */
    @Override
    public PaymentRule selectPaymentRuleById(Long ruleId)
    {
        return this.getById(ruleId);
    }

    /**
     * 查询付费规则列表
     *
     * @param paymentRule 付费规则
     * @return 付费规则
     */
    @Override
    public List<PaymentRule> queryList(PaymentRule paymentRule)
    {
        QueryWrapper<PaymentRule> queryWrapper = Wrappers.query();
                                        if (StringUtils.isNotEmpty(String.valueOf(paymentRule.getRuleId()))&&paymentRule.getRuleId()!=null)
        {
            queryWrapper.eq("RULE_ID", paymentRule.getRuleId());
        }
                                                if (StringUtils.isNotEmpty(String.valueOf(paymentRule.getPlatformId()))&&paymentRule.getPlatformId()!=null)
        {
            queryWrapper.eq("PLATFORM_ID", paymentRule.getPlatformId());
        }
                                                if (StringUtils.isNotEmpty(String.valueOf(paymentRule.getPeriodValidity()))&&paymentRule.getPeriodValidity()!=null)
        {
            queryWrapper.eq("PERIOD_VALIDITY", paymentRule.getPeriodValidity());
        }
                                                if (StringUtils.isNotEmpty(String.valueOf(paymentRule.getPrice()))&&paymentRule.getPrice()!=null)
        {
            queryWrapper.eq("PRICE", paymentRule.getPrice());
        }
                                                if (StringUtils.isNotEmpty(String.valueOf(paymentRule.getPeriodValidityNumber()))&&paymentRule.getPeriodValidityNumber()!=null)
        {
            queryWrapper.eq("PERIOD_VALIDITY_NUMBER", paymentRule.getPeriodValidityNumber());
        }
                                                                                                                if (StringUtils.isNotEmpty(String.valueOf(paymentRule.getCreateUser()))&&paymentRule.getCreateUser()!=null)
        {
            queryWrapper.eq("CREATE_USER", paymentRule.getCreateUser());
        }
                                                if (StringUtils.isNotEmpty(String.valueOf(paymentRule.getUpdateUser()))&&paymentRule.getUpdateUser()!=null)
        {
            queryWrapper.eq("UPDATE_USER", paymentRule.getUpdateUser());
        }
                        return paymentRuleMapper.selectList(queryWrapper);
    }

    /**
     * 新增付费规则
     *
     * @param paymentRule 付费规则
     * @return 结果
     */
            @Override
    public boolean insertPaymentRule(PaymentRule paymentRule)
    {

        return this.save(paymentRule);

    }

    /**
     * 修改付费规则
     *
     * @param paymentRule 付费规则
     * @return 结果
     */
            @Override
    public boolean updatePaymentRule(PaymentRule paymentRule)
    {

        return this.updateById(paymentRule);
    }

    /**
     * 批量删除付费规则
     *
     * @param ruleIds 需要删除的付费规则ID
     * @return 结果
     */
            @Override
    public boolean deletePaymentRuleByIds(Long[] ruleIds)
    {
        return this.removeByIds(Arrays.asList(ruleIds));
    }




}
